package fleditor.view
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	
	import fleditor.controller.FlEditorController;
	import fleditor.events.AssetEvent;
	import fleditor.events.FlEditorEvent;
	import fleditor.model.FlEditorModel;
	import fleditor.view.assetView.AssetFodderListView;
	import fleditor.view.assetView.AssetListView;

	public class AssetView extends Sprite
	{
		/**
		 *主场景 
		 */		
		private var _stage:Stage;
		
		/**
		 *全局Model类(FlEditModel)
		 */		
		private var _model:FlEditorModel;
		
		/**
		 *全局控制器(FlEditorController) 
		 */		
		private var _controller:FlEditorController;
		
		/**
		 *物件单项列表视图 
		 */		
		private var _assetListView:AssetListView;
		
		/**
		 *物件素材列表视图 
		 */		
		private var _assetFodderListView:AssetFodderListView;
		
		public function AssetView(stage:Stage, controller:FlEditorController, model:FlEditorModel)
		{
			_stage=stage;
			_controller=controller;
			_model=model;
			setView();
			setEvent();
		}
		
		private function setView():void
		{
			resetUI();
		}
		
		/**
		 *事件设置 
		 * 
		 */		
		private function setEvent():void
		{
			_stage.addEventListener(Event.RESIZE, __onStageResize);
			_controller.addEventListener(AssetEvent.MENU_ASSET_ACTION_TYPE, __onMenuAssetAction);
		}
		
		/**
		 *当舞台窗口改变大小 
		 * @param evt
		 * 
		 */		
		private function __onStageResize(evt:Event):void
		{
			resetUI();
		}
		
		/**
		 *设定当前物件编辑功能视图（对应物件编辑二级操作菜单） 
		 * @param evt
		 * 
		 */	
		private function __onMenuAssetAction(evt:AssetEvent):void
		{
			switch(evt.date)
			{
				case 1://单项编辑
					if(!_assetListView) _assetListView=new AssetListView(_controller, _model);
					addChild(_assetListView);
					
					if(!_assetFodderListView) _assetFodderListView=new AssetFodderListView(_stage, _controller, _model);
					_assetFodderListView.x=_stage.stageWidth-160-6;
					addChild(_assetFodderListView);
					break;
			}
		}
		
		/**
		 *重置视图界面 
		 * 
		 */		
		private function resetUI():void
		{
			if(_assetFodderListView) _assetFodderListView.x=_stage.stageWidth-160-6;//重置素材库列表
		}
	}
}